﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Donate.DAl;

namespace Donate
{
    public partial class userName : Form
    {
        public userName()
        {
            InitializeComponent();
        }

        private userNameEntity getEntityFromForm()
        {
            userNameEntity u = new userNameEntity();
            if (txtPass.Text == txtpass2.Text)
            {
               
                u.ID = txtPass.Text;
                u.user_Name = txtUserName.Text;
                return u;
            }
            else
            {
                MessageBox.Show("خطأ فى كلمة السر");
                return null;
            }
            
        }
        private void publishToForm(userNameEntity u)
        {
            txtUserName.Text = u.user_Name;
            txtPass.Text = u.ID;
        }
        private void clearForm()
        {
            txtUserName.Text = "";
            txtPass.Text = "";

        }

        private void bttnSave_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(txtUserName.Text))
            {
                List<userNameEntity> listName = userNames.GetByMemNameAndId(txtUserName.Text,txtPass.Text);
                if (listName.Count == 0)
                {
                    if (getEntityFromForm() != null)
                    {
                        if (userNames.insert(getEntityFromForm()))
                        {
                            MessageBox.Show("تم الحفظ بنجاح");
                        }
                        else
                        {
                            MessageBox.Show("خطأ فى الحفظ");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("هذا العضو مسجل من قبل");
                }
            }
            else
            {
                MessageBox.Show("يحب إدخال البيانات كاملة");
            }
        }

        private void bttnClear_Click(object sender, EventArgs e)
        {
            clearForm();
        }


    }
}
